home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_354 / mxmlib / libstartup.asm < prev    next >
Assembly Source File  |  1992-05-06  |  4KB  |  119 lines

  1. *--------------------------------------------------------------------*
  2. *    Library startup module, not as funky as Jimm's example
  3. *    Aztec code, but (hopefully) okay for Aztec 5.0.
  4. *
  5. *    Note:    Register usage has been rearranged to allow
  6. *        library init call with parameters in registers.
  7. *
  8. *    Based on LibStart.A68 (with some of the bugs taken out),
  9. *    Copyright (C) 1986, 1987 by Manx Software Systems, Inc.
  10. *--------------------------------------------------------------------*
  11.  
  12.     INCLUDE    'exec/types.i'
  13.     INCLUDE    'exec/nodes.i'
  14.     INCLUDE    'exec/resident.i'
  15.  
  16. *--------------------------------------------------------------------*
  17. *    Here we start the code generation.
  18. *--------------------------------------------------------------------*
  19.  
  20.     SECTION    RomTag,CODE
  21.  
  22. *--------------------------------------------------------------------*
  23. *    Not very executable (also does long word alignment).
  24. *--------------------------------------------------------------------*
  25.  
  26.     MOVEQ    #-1,D0            ; Fail if run from anywhere
  27.     RTS
  28.  
  29. *--------------------------------------------------------------------*
  30. *    Library version, this should match the lib ID string.
  31. *--------------------------------------------------------------------*
  32.  
  33. LIBVERSION    EQU    34
  34.  
  35. *--------------------------------------------------------------------*
  36. *    Global symbols (rather in a bunch than sprenkled).
  37. *--------------------------------------------------------------------*
  38.  
  39.     PUBLIC    _LibRomTag,_LibName,_LibId,_LibInitTab,_LibInit
  40.     PUBLIC    _LibMain,.begin,_geta4,__H0_org
  41.  
  42. *--------------------------------------------------------------------*
  43. *    The RomTag structure, must be in first hunk.
  44. *--------------------------------------------------------------------*
  45.  
  46. _LibRomTag:
  47.  
  48.     DC.W    RTC_MATCHWORD        ; Tag ID (680x0 ILLEGAL)
  49.  
  50.     DC.L    _LibRomTag        ; Points to beginning of tag
  51.     DC.L    _LibEndTag        ; Points to end of tag
  52.  
  53.     DC.B    RTF_AUTOINIT        ; Auto init library
  54.     DC.B    LIBVERSION        ; Library version
  55.     DC.B    NT_LIBRARY        ; This is a library, not a device
  56.     DC.B    0            ; Priority (leave it zero)
  57.  
  58.     DC.L    _LibName        ; Pointer to lib name (e.g. 'any.library')
  59.     DC.L    _LibId            ; Pointer to lib ID (e.g. 'any.library (31 Feb 1103)')
  60.     DC.L    _LibInitTab        ; Pointer to library init table
  61.  
  62. _LibEndTag:
  63.  
  64. *--------------------------------------------------------------------*
  65. *    This is supposed to be the lib entry point.
  66. *--------------------------------------------------------------------*
  67.  
  68. .begin                    ; First hunk
  69.  
  70. *--------------------------------------------------------------------*
  71. *    Sets up the lib environment and calls the main init routine.
  72. *
  73. *    Register usage:    D0 - APTR to library base
  74. *            A0 - BPTR to libray segment list
  75. *
  76. *    Main init routine is expected to return the library base
  77. *    in D0 if library is ready to be used.
  78. *--------------------------------------------------------------------*
  79.  
  80. _LibInit:
  81.  
  82.     MOVEM.L    D2-D7/A2-A6,-(SP)    ; Save registers
  83.     BSR    _geta4            ; Get A4
  84.     LEA    __H1_end,A1
  85.     LEA    __H2_org,A2
  86.     CMP.L    A1,A2            ; Check if BSS and DATA together
  87.     BNE    Start            ; No, don't have to clear
  88.     MOVE.W    #((__H2_end-__H2_org)/4)-1,D1
  89.     BMI    Start            ; Skip if no bss
  90.  
  91.     MOVEQ    #0,D2
  92. Loop    MOVE.L    D2,(A1)+        ; Clear out memory
  93.     DBRA    D1,Loop
  94.  
  95. Start    MOVE.L    A6,_SysBase        ; Put it where we can get it
  96.     JSR    _LibMain
  97.  
  98.     MOVEM.L    (SP)+,D2-D7/A2-A6    ; Restore registers
  99.     RTS                ; And return
  100.  
  101. *--------------------------------------------------------------------*
  102. *    Sets A4 up to point into the middle of the data segment.
  103. *--------------------------------------------------------------------*
  104.  
  105. _geta4:    FAR    DATA
  106.     LEA    __H1_org+32766,A4
  107.     RTS
  108.  
  109. *--------------------------------------------------------------------*
  110. *    Data segment (globals/hunks).
  111. *--------------------------------------------------------------------*
  112.  
  113.     SECTION    LibData,DATA
  114.  
  115.     PUBLIC    _SysBase,__H1_org,__H1_end,__H2_org,__H2_end
  116.     BSS    _SysBase,4
  117.  
  118.     END
  119.